package net.lcqf.udp.send.message;

import cn.hutool.json.JSONUtil;
import net.lcqf.udp.kcp.Ukcp;
import net.lcqf.udp.request.PingRequest;
import net.lcqf.udp.response.PingResponse;
import net.lcqf.udp.send.MessageBaseService;
import net.lcqf.udp.send.MessageFactory;
import net.lcqf.udp.send.RequestType;
import net.lcqf.udp.server.MsgInfo;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 * +----------------------------------------------------------------------
 * // | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
 * // +----------------------------------------------------------------------
 * // | Copyright (c) 2021-2025 聊来 All rights reserved.
 * // +----------------------------------------------------------------------
 * // | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">apache</a> )
 * // +----------------------------------------------------------------------
 * // | @Author: 聊来 <18970881148@qq.com>
 * // +----------------------------------------------------------------------
 * // | DateTime: 2025/4/16 18:49
 * // +----------------------------------------------------------------------
 */
@Service
public class Ping implements MessageBaseService {

    @PostConstruct
    @Override
    public void init() { MessageFactory.register(RequestType.PING.getCustomOrdinal(), this);}


    @Override
    public Object sendMessage(Ukcp kcp, MsgInfo msgInfo) {
        PingRequest request = JSONUtil.toBean(msgInfo.getData(), PingRequest.class);

        PingResponse response = new PingResponse();
        response.setPingId(request.getPingId());

        return response;
    }
}
